package com.hc.fdkgoods.dao;

import com.hc.fdkgoods.vo.vo_7.SpuIdListInputVO;
import com.hc.fdkgoods.vo.vo_7.SpuIdListOutputVO;
import com.hc.fdkgoods.vo.vo_7.SpuIdOutputVO;
import org.springframework.stereotype.Repository;

import static com.hc.fdkgoods.db.Tables.*;

@Repository
public class SpuIdListDao extends BaseDao {
    public SpuIdListOutputVO getSpuIdList(SpuIdListInputVO spuIdList) {
        SpuIdListOutputVO res = new SpuIdListOutputVO();

        for (Long data : spuIdList.getSpuIdList()) {

            res.setList(db.select(
                    FORWARDER_SUPPLIER.CITY_CODE,
                    FORWARDER_SUPPLIER.CITY.as("cityName"),
                    FORWARDER_SUPPLIER.BUSINESS.as("businessName"),
                    FORWARDER_SUPPLIER.FLOOR_CODE,
                    FORWARDER_SUPPLIER.FLOOR.as("floorName"),
                    FORWARDER_SUPPLIER.FORWARDER_SUPPLIER_ID,
                    FORWARDER_SUPPLIER.MARKET_CODE,
                    FORWARDER_SUPPLIER.MARKET.as("marketName"),
                    FORWARDER_SUPPLIER.SUPPLIER_NAME,
                    SELLER_SPU.GOODS_NO,
                    SELLER_SPU.MAIN_IMG_URL.as("spuImg"),
                    SELLER_SPU.SPU_NAME,
                    MAP_SELLER_SKU_SUPPLIER.ITEM_NO,
                    MAP_SELLER_SKU_SUPPLIER.PURCHASE_PRICE,
                    MAP_SELLER_SKU_SUPPLIER.REMARK,
                    MAP_SELLER_SKU_SUPPLIER.SELLER_SKU_ID,
                    MAP_SELLER_SKU_SUPPLIER.SELLER_SPU_ID)
                    .from(MAP_SELLER_SKU_SUPPLIER)
                    .innerJoin(FORWARDER_SUPPLIER)
                    .on(FORWARDER_SUPPLIER.FORWARDER_SUPPLIER_ID.eq(MAP_SELLER_SKU_SUPPLIER.SUPPLIER_ID))
                    .innerJoin(SELLER_SPU)
                    .on(MAP_SELLER_SKU_SUPPLIER.SELLER_SPU_ID.eq(data))
                    .where(MAP_SELLER_SKU_SUPPLIER.SELLER_SPU_ID.eq(data)).fetchInto(SpuIdOutputVO.class));
            System.out.println(res);
        }
        return res;
    }
}
